package com.weex.app.module.tool;

import android.app.Activity;
import android.graphics.Bitmap;

import com.abe.libphoto.BitmapUtil;
import com.taobao.weex.annotation.JSMethod;
import com.taobao.weex.bridge.JSCallback;
import com.taobao.weex.common.WXModule;

import java.util.HashMap;
import java.util.Map;

public class ToolModule extends WXModule {
    @JSMethod
    public void bitmapToString(Bitmap bitmap, JSCallback callback) {
        Map<String, Object> map = new HashMap<>();
        map.put("base64Img", ImageUtils.bitmapToString(bitmap));
        callback.invokeAndKeepAlive(map);
    }

    @JSMethod
    public void stringToBitmap(String imgString, JSCallback callback) {
        Map<String, Object> map = new HashMap<>();
        map.put("bitmap", ImageUtils.stringToBitmap(imgString));
        callback.invokeAndKeepAlive(map);
    }

    @JSMethod
    public void imgPathToBitmap(String path, JSCallback callback) {
        Map<String, Object> map = new HashMap<>();
        map.put("base64Img", ImageUtils.bitmapToString(BitmapUtil.readLocalBitmap(path)));
        callback.invokeAndKeepAlive(map);
    }

    @JSMethod
    public void showLoadDialog() {
        LoadDialog.show((Activity) mWXSDKInstance.getContext());
    }

    @JSMethod
    public void hideLoadDialog() {
        LoadDialog.hide((Activity) mWXSDKInstance.getContext());
    }
}
